<?php
class ModelWebIndex extends Model {
	public function getSetting() {
		$query = $this->db->query("SELECT * FROM web_config ORDER BY id");
		return $query->rows;
	}
	public function editSetting($data) {
		$this->db->query("DELETE FROM web_config");
		$input = array();
		foreach ($data['shop_reason'] as $v) {
			$input[] = "('" . $this->db->escape($v) . "',1,'')";
		}
		$input[] = "('" . $data['blog_num'] . "',2,'')";
		$input[] = "('" . $this->db->escape($data['search_key']) . "',3,'')";
		foreach ($data['focus_pic'] as $k => $v) {
			if (trim($v) != "") {
				$input[] = "('" . $this->db->escape($v) . "',4,'" . $this->db->escape($data['url_' . $k]) . "')";
			}
		}
		$input[] = "('" . $this->db->escape($data['register']) . "',5,'')";
		$this->db->query("INSERT INTO web_config(content,type,href)VALUES " . implode($input, ","));
	}
	public function getFriend($data) {
		$start = ($data['page']) * $this->config->get('config_admin_limit');
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "friend_link ORDER BY id LIMIT $start," . $this->config->get('config_admin_limit'));
		return $query->rows;
	}
	public function getFriendTotal() {
		$query = $this->db->query("SELECT count(*) AS total FROM " . DB_PREFIX . "friend_link");
		return $query->row['total'];
	}
	public function updateFriend($data) {
		return $query = $this->db->query("UPDATE " . DB_PREFIX . "friend_link SET `show`=" . $data['status'] . " WHERE id=" . $data['id']);
	}
	public function delFriend($id) {
		return $query = $this->db->query("DELETE FROM " . DB_PREFIX . "friend_link  WHERE id=" . $id);
	}
}